package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MerchantPublishDeviceGroup 商户投放设备分组表
type MerchantPublishDeviceGroup struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	MerchantID string `json:"merchant_id" gorm:"column:merchant_id;primaryKey;type:varchar(30);not null;default:'';index:merchant_id,unique;comment:商户id"`
	GroupID    string `json:"group_id" gorm:"column:group_id;type:int;size:64;not null;default:0;comment:分组id"`
}

// TableName 表名
func (MerchantPublishDeviceGroup) TableName() string {
	return "merchant_publish_device_group"
}

// BeforeCreate 自增id
func (l *MerchantPublishDeviceGroup) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MerchantPublishDeviceGroup{})
}
